package com.zwl.springcloud.controller;



import com.zwl.springcloud.entity.Result;
import com.zwl.springcloud.service.MobileApppaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Component
@RequestMapping("/app/pay")
public class MobileApppaymentController {

    @Autowired
    private MobileApppaymentService mobileApppaymentService;

    /**
     * 发起支付
     * @param params 入参
     * @Value title(String)：商品标题，
     * describe（String）:商品描述，
     * uiqueStatus（String）:用户唯一标识
     * price(float):价格
     * @return
     */
    @PostMapping("/WeChatPay")
    @ResponseBody
    public Result<Map<String,Object>> setPay(@RequestBody Map<String, Object> params) {
        Map<String,Object> map;
        try {
            map= mobileApppaymentService.getUrl(params);
            return new Result("支付成功",200,map);
        }catch (Exception e){
            e.printStackTrace();
            return new Result("支付失败",403,null);
        }

    }

}

